﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {


            double[] kontoStand = new double[25];
            double[] letzteBuchung = new double[25];
            string[] Kontoname = new string[25];
            int i = 0;
            int a = 0;
            // int n = 0;
            int b = 0;
        

        

        public Form1()
        {
            InitializeComponent();

            kontoStand[0] = 2500;
            kontoStand[1] = 400;
            kontoStand[2] = 50;

            Kontoname[0] = "Andre";
            Kontoname[1] = "Tobi";
            Kontoname[2] = "Robert";

            for (int n = 0; n <= 2; n++)
            {
                cbAuswahl.Items.Add(Kontoname[n]);
            }
            

        }

        private void btBuchen_Click(object sender, EventArgs e)
        {
            i = Convert.ToInt32(cbAuswahl.SelectedIndex);


            letzteBuchung[i] = Convert.ToDouble(tbBuchung.Text);
            if ((kontoStand[i] + letzteBuchung[i]) >= 0.0)
            {
                kontoStand[i] = letzteBuchung[i] + kontoStand[i];
                Lbuchung2.Text = Convert.ToString(letzteBuchung[i] + "€");
                Lstand2.Text = Convert.ToString(kontoStand[i] + "€");

            }
            else
            {
                MessageBox.Show("Konto kann nicht überzogen werden!");
            }
            
        }

        private void btnewanlegen_Click(object sender, EventArgs e)
        {
            a = Array.IndexOf(Kontoname, Kontoname[Kontoname.Length - 1]);    
            
           // Lstand2.Text = Convert.ToString(a + "€");
            if (a >= 24)
            {
                MessageBox.Show("Kein Speicherplatz zur Verfügung!");
            }
            else
            {
                Kontoname[a] = Convert.ToString(tbnewname.Text);
                cbAuswahl.Items.Add(Kontoname[a]);
                if (tbnewstand.Text == "Bitte aktuellen Kontostand eintragen...")
                {
                    MessageBox.Show("Bitte Kontostand angeben");
                }
                else
                {
                    kontoStand[a] = Convert.ToInt32(tbnewstand.Text);
                    cbAuswahl.SelectedIndex = a;
                    Lstand2.Text = Convert.ToString(kontoStand[a] + "€");
                }
            }
       
           




        }

        private void cbAuswahl_SelectedIndexChanged(object sender, EventArgs e)
        {
            i = Convert.ToInt32(cbAuswahl.SelectedIndex);

            Lbuchung2.Text = Convert.ToString(letzteBuchung[i] + "€");
            Lstand2.Text = Convert.ToString(kontoStand[i] + "€");

        }

        private void tbnewname_Click(object sender, EventArgs e)
        {
            tbnewname.Clear();
        }

        private void tbnewstand_Click(object sender, EventArgs e)
        {
            tbnewstand.Clear();
        }




        
    }
}
